//判断浏览器
var userAgent = navigator.userAgent, isIE = false;
if (userAgent.indexOf('MSIE') != -1) {
    isIE = true;
}

//查找对象
function MM_findObj(n, d) { //v4.0
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && document.getElementById) x = document.getElementById(n); return x;
}

//显示隐藏通知层
function MM_showHideLayers() { //v6.0
    var i, p, v, obj, args = MM_showHideLayers.arguments;
    for (i = 0; i < (args.length - 2); i += 3) if ((obj = MM_findObj(args[i])) != null) {
        v = args[i + 2];
        if (obj.style) { obj = obj.style; v = (v == 'show') ? 'visible' : (v == 'hide') ? 'hidden' : v; }
        obj.visibility = v;
    }
}

//隐藏显示层，加强版
function MM_showHideLayers_pro() { //v9.0
    var i, p, v, obj, args = MM_showHideLayers_pro.arguments;
    for (i = 0; i < (args.length - 2); i += 3)
        with (document) if (getElementById && ((obj = getElementById(args[i])) != null)) {
        v = args[i + 2];
        if (obj.style) { obj = obj.style; v = (v == 'show') ? 'block' : (v == 'hide') ? 'none' : v; }
        obj.display = v;
    }
}

//交换图象存储
function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

//预载入图象
function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; }
    }
}

//交换图象
function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}

//设置控件的HTML
function SetControlHTML(obj, str) {
    MM_findObj(obj).innerHTML = str;
}

//更换控件的css样式
function ChangeClassName(obj, classname) {
    obj.className = classname;
}

//重新获取验证码
function ReGetVerifyCode(myIMG) {
    MM_findObj(myIMG).src = "VerifyCodeImg.aspx?ID=" + MM_GetTime();
}

//ASCII字符长度
String.prototype.len = function() {
    return this.replace(/[^x00-xff]/g, "**").length;
}

//去掉字符串头部和尾部的空格
String.prototype.trim = function() {
    //   用正则表达式将前后空格   
    //   用空字符串替代。   
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

//截取字符串前面几个字符（按英文字节算、带省略号）
String.prototype.sub = function(n) {
    var r = /[^\x00-\xff]/g;
    if (this.replace(r, "mm").length <= n) return this;
    // n = n - 3;     
    var m = Math.floor(n / 2);
    for (var i = m; i < this.length; i++) {
        if (this.substr(0, i).replace(r, "mm").length >= n) {
            return this.substr(0, i) + "...";
        }
    } return this;
};

//获取xmlhttp对象
function GetXmlHttpRequest() {
    var oBao;
    if (window.XMLHttpRequest) {
        oBao = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        oBao = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else {
        alert("您的浏览器不支持XMLHTTP无刷新技术！");
        return;
    }
    return oBao;
}

//获取时间
function MM_GetTime() {
    var d = new Date();
    return d.getTime();
}

//添加cookie
function addCookie(objName, objValue, objHours) {//添加cookie
    var str = objName + "=" + escape(objValue);
    if (objHours > 0) {//为0时不设定过期时间，浏览器关闭时cookie自动消失
        var date = new Date();
        var ms = objHours * 3600 * 1000;
        date.setTime(date.getTime() + ms);
        str += "; expires=" + date.toGMTString();
    }
    document.cookie = str;
}

//获取指定名称的cookie的值
function getCookie(objName) {
    var arrStr = document.cookie.split("; ");
    for (var i = 0; i < arrStr.length; i++) {
        var temp = arrStr[i].split("=");
        if (temp[0] == objName) return unescape(temp[1]);
    }
}

//为了删除指定名称的cookie，可以将其过期时间设定为一个过去的时间
function delCookie(name) {
    var date = new Date();
    date.setTime(date.getTime() - 10000);
    document.cookie = name + "=a; expires=" + date.toGMTString();
}

//读取出来所有的cookie字筗串了
function allCookie() {//读取所有保存的cookie字符串
    var str = document.cookie;
    if (str == "") {
        str = "没有保存任何cookie";
    }
    alert(str);
}

//添加收藏
function AddFavorite(sURL, sTitle) {
    try {
        sURL = window.location.href;
        window.external.addFavorite(sURL, sTitle);
    }
    catch (e) {
        try {
            window.external.addToFavoritesBar(sURL, sTitle, 'slice');
        }
        catch (e) {
            try {
                window.sidebar.addPanel(sTitle, sURL, "");
            }
            catch (e) {
                alert("加入收藏失败，请使用Ctrl+D进行添加");
            }
        }
    }
}

//设为首页
function SetHome(obj, vrl) {
    try {
        vrl = window.location.href;
        obj.style.behavior = 'url(#default#homepage)'; obj.setHomePage(vrl);
    }
    catch (e) {
        if (window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            }
            catch (e) {
                alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入\"about:config\"并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。");
            }
            var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
            prefs.setCharPref('browser.startup.homepage', vrl);
        }
    }
}

//图片切换
function ChangeBigPic(disObj, obj) {
    MM_findObj(disObj).src = obj.src;
}